Return Statement Confusion

Greetings,

I am trying to create a return statement, but I don't know what i'm doing wrong.
 

Folder f = current
Item i
 
bool isFormal(Item i)
{
string iType = type(i)
    if(iType == "Formal")
        {
                return true
        }
}
 
for i in f do
{
        if(isFormal(i))
        {
                print name(i)
        }
}

SystemAdmin - Wed Nov 11 15:20:59 EST 2009

Re: Return Statement Confusion
doors36677 - Wed Nov 11 16:20:43 EST 2009

You must have a return state for the first block as shown

bool isFormal(Item i)
{ string iType = type(i)
  if(iType == "Formal") return true
  return false
}

Re: Return Statement Confusion
llandale - Fri Nov 13 10:47:02 EST 2009

Yes. You are getting the run time error "function terminated without executing return statement" when you encounter a sub-folder.

'void' functions may have a no-parameter 'return' statement. There is an implicit 'return' at the bottom of the function:

void  LogIt(string Message)
{
    if (null Message) return
    Log the Message
}  // implicit return here


Variable functions must have a parameter 'return' statement for all possible paths through the function. It therefore makes little sense to have a statement at the bottom of the function that's not a return(variable), although some sort of if-then-else may be an exception.

 

int   GetIt(string Name)
{
     if (null Name) return(-1)
     string Temp = upper(Name)
     if     (Temp == "A") return(0)
     elseif(Temp == "B") return(1)
     elseif(Temp == "C") return(2)
     else                return(3)
          // all cases are covered in the if-else clause; no return needed here
     print "this statment can never execute\n"
     return(-1)   // Just in case, this is good practice
}

 

 

 

  • Louie